﻿using System.Collections.Generic;

namespace Hourglass.Qrobot.Models
{
    public abstract class QqMessage
    {
        /// <summary>
        /// 消息类型
        /// </summary>
        public abstract MessageType Type { get; }

        /// <summary>
        /// 消息来源QQ号
        /// </summary>
        public PersonInfo FromQq { get; set; }

        /// <summary>
        /// 消息中被@的QQ列表
        /// </summary>
        public List<PersonInfo> AtQqList { get; set; }

        /// <summary>
        /// 去除@人的内容拼接部分
        /// </summary>
        public string NoAtContent { get; set; }

        /// <summary>
        /// 完整消息内容
        /// </summary>
        public string FullContent { get; set; }

        protected QqMessage()
        {
            AtQqList = new List<PersonInfo>();
        }

        public bool TypeEquals(MonitorType type)
        {
            if (type == MonitorType.All) return true;
            if (type == MonitorType.Personal && Type == MessageType.Personal) return true;
            if (type == MonitorType.Group && Type == MessageType.Group) return true;
            if (type == MonitorType.Disscuss && Type == MessageType.Disscuss) return true;
            return false;
        }

        #region Internal Class
        public enum MessageType
        {
            /// <summary>
            /// 踢下线
            /// </summary>
             Kick,
             /// <summary>
             /// 个人消息
             /// </summary>
             Personal,
             /// <summary>
             /// QQ群组消息
             /// </summary>
             Group,
             /// <summary>
             /// 讨论组消息
             /// </summary>
             Disscuss,
             /// <summary>
             /// 异常消息
             /// </summary>
            Error
        }

        public sealed class PersonInfo
        {
            //internal long Id { get; set; }

            public long Qq { get; set; }

            /// <summary>
            /// 昵称
            /// </summary>
            public string NickName { get; set; }

            /// <summary>
            /// 备注名称/名片
            /// </summary>
            public string MarkName { get; set; } 
        }
        #endregion Internal Class
    }

    /// <summary>
    /// 被踢下线的QQ消息
    /// </summary>
    public sealed class KickMessage : QqMessage
    {
        public override MessageType Type => MessageType.Kick;

        /// <summary>
        /// 下线原因
        /// </summary>
        public string OfflineMark { get; set; }

        public KickMessage(string offlineMark)
        {
            this.OfflineMark = offlineMark;
        }
    }

    /// <summary>
    /// 异常消息
    /// </summary>
    public sealed class ErrorMessage : QqMessage
    {
        public override MessageType Type => MessageType.Error;

        /// <summary>
        /// 错误信息
        /// </summary>
        public string ErrorInfo { get; set; }

        public ErrorMessage(string errorInfo)
        {
            this.ErrorInfo = errorInfo;
        }
    }

    /// <summary>
    /// 个人QQ消息
    /// </summary>
    public sealed class PersonalMessage : QqMessage
    {
        public override MessageType Type => MessageType.Personal;
    }

    public sealed class GroupMessage : QqMessage
    {
        public override MessageType Type => MessageType.Group;

        /// <summary>
        /// 群号
        /// </summary>
        public long GroupNumber { get; set; }

        /// <summary>
        /// 群名称
        /// </summary>
        public string GroupName { get; set; }
    }

    /// <summary>
    /// 讨论组消息
    /// </summary>
    public sealed class DisscussMessage : QqMessage
    {
        public override MessageType Type => MessageType.Disscuss;

        /// <summary>
        /// 讨论组名称
        /// </summary>
        public string DisscussName { get; set; }
    }
}
